#include "gtest/gtest.h"
#include "robot_cleaner.h"

// 测试初始化位姿
TEST(RobotCleanerTest, InitPosition) {
    RobotCleaner robot;
    EXPECT_EQ(Position(0, 0, NORTH), robot.getPosition());
}

// 测试指定位姿
TEST(RobotCleanerTest, SpecifiedPosition) {
    RobotCleaner robot(1, 2, SOUTH);
    EXPECT_EQ(Position(1, 2, SOUTH), robot.getPosition());
}

// 测试原始位置左转
TEST(RobotCleanerTest, TurnLeftCommand) {
    RobotCleaner robot;
    Command* command = CommandFactory::createCommand(TURN_LEFT);
    robot.executeCommand(command);
    EXPECT_EQ(Position(0, 0, WEST), robot.getPosition());
}

// 测试原始位置右转
TEST(RobotCleanerTest, TurnRightCommand) {
    RobotCleaner robot;
    Command* command = CommandFactory::createCommand(TURN_RIGHT);
    robot.executeCommand(command);
    EXPECT_EQ(Position(0, 0, EAST), robot.getPosition());
}

// 测试原始位置四个方向前进
TEST(RobotCleanerTest, ForwardCommand) {
    const int dx[4] = {0, 1, 0, -1};
    const int dy[4] = {1, 0, -1, 0};
    for (int i = 0; i < 4; i++) {
        Direction d = Direction(i);
        RobotCleaner robot(0, 0, d);
        Command* command = CommandFactory::createCommand(FORWARD);
        robot.executeCommand(command);
        EXPECT_EQ(Position(dx[i], dy[i], d), robot.getPosition())
            << "Failed at " << i << std::endl;
    }
}

// 测试原始位置四个方向后退
TEST(RobotCleanerTest, BackwardCommand) {
    const int dx[4] = {0, -1, 0, 1};
    const int dy[4] = {-1, 0, 1, 0};
    for (int i = 0; i < 4; i++) {
        Direction d = Direction(i);
        RobotCleaner robot(0, 0, d);
        Command* command = CommandFactory::createCommand(BACKWARD);
        robot.executeCommand(command);
        EXPECT_EQ(Position(dx[i], dy[i], d), robot.getPosition())
            << "Failed at " << i << std::endl;
    }
}

// 测是原地掉头ROUND
TEST(RobotCleanerTest, RoundCommand) {
    RobotCleaner robot(0, 0, NORTH);
    Command* command = CommandFactory::createCommand(ROUND);
    robot.executeCommand(command);
    EXPECT_EQ(Position(0, 0, SOUTH), robot.getPosition());
}